package naruto.datastructures.graph;

import naruto.common.*;

/**
 *
 * @author nacuong
 */
public class Edge {
  GraphCommon.EdgeAttribute attribute;
  GraphCommon.EdgeStatus status;
  Node source;
  Node target;

  public Edge(Node source, Node target, GraphCommon.EdgeStatus status){
    this.source = source;
    this.target = target;
    this.status = status;

    if (source instanceof IfNode)
      if (((IfNode)source).getInstruction().getConditionValue())
        attribute = GraphCommon.EdgeAttribute.TRUE;
      else attribute = GraphCommon.EdgeAttribute.FALSE;
    else
      attribute = GraphCommon.EdgeAttribute.NONE;
  }

  public Edge(Node source, Node target, GraphCommon.EdgeAttribute attribute, GraphCommon.EdgeStatus status){
    this.source = source;
    this.target = target;
    this.attribute = attribute;
    this.status = status;
  }

  public boolean equals(Object edge){
    return edge instanceof Edge
            && source.equals(((Edge)edge).getSource())
            && target.equals(((Edge)edge).getTarget())
            && attribute.equals(((Edge)edge).getAttribute())
            && status.equals(((Edge)edge).getStatus());
  }

  public Node getSource(){
    return source;
  }

  public Node getTarget(){
    return target;
  }

  public GraphCommon.EdgeAttribute getAttribute(){
    return attribute;
  }

  public GraphCommon.EdgeStatus getStatus(){
    return status;
  }

  public boolean isConcrete(){
    return !isAbstract();
  }

  public boolean isAbstract(){
    return status.equals(GraphCommon.EdgeStatus.ABSTRACT);
  }

  public boolean isFalseAttribute(){
    return attribute.equals(GraphCommon.EdgeAttribute.FALSE);
  }

  public boolean isTrueAttribute(){
    return attribute.equals(GraphCommon.EdgeAttribute.TRUE);
  }
}
